<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="../node_modules/vue/dist/vue.js"></script>
<div id="app">
    <h2>当前计数：{{counter}}</h2>
    <button @click="add">+</button>
    <button @click="sub">-</button>
</div>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            counter:0
        },
        methods:{
            add(){
                this.counter++
            },
            sub(){
                this.counter--
            }
        },
        watch:{
            handler(newVal) {
                console.log(newVal);
            }
        },
        beforeCreate(){
            console.log('beforeCreat');
        },
        created(){
            //如果要请求后端的数据，多在此时请求
            console.log('created')
        },
        mounted(){
            //html代码片段已经挂载完成至虚拟domha
            console.log('mounted');
        }


    
    })
</script>
</body>
</html>